import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/modules/model/goods_entity.dart';
import 'package:mall/utils/image_component/image_component.dart';

typedef ItemClick(int value);

class GoodsWidget extends StatelessWidget {
  final GoodsEntity _goodsEntity;
  final ItemClick? _itemClick;

  GoodsWidget(this._goodsEntity, this._itemClick);

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: Container(
        child: InkWell(
          child: Card(
            child: Container(
                alignment: Alignment.center,
                child: Column(
                  children: <Widget>[
                    AspectRatio(
                      aspectRatio: 1.0,
                      child: ImageComponent(
                        _goodsEntity.picUrl,
                      ),
                    ),
                    SizedBox(height: 2),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.only(left: 10, right: 10, bottom: 10),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            //标题
                            Text(
                              _goodsEntity.name ?? "",
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                color: AppColors.C_222222,
                                fontSize: 13,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            SizedBox(height: 2),
                            //标签
                            Text('智能伸缩 | 玻尿酸',
                                style: TextStyle(
                                  color: AppColors.C_666666,
                                  fontSize: 12.sp,
                                )),
                            Spacer(),
                            //价格和销量
                            Row(
                              children: [
                                //价格
                                _price(),
                                Spacer(),
                                //销量
                                Text(
                                  "已售${11}",
                                  style: TextStyle(
                                    color: AppColors.C_848484,
                                    fontSize: 11.sp,
                                  ),
                                )
                              ],
                            )
                          ],
                        ),
                      ),
                    ),
                  ],
                )),
          ),
          onTap: () => _itemClick?.call(_goodsEntity.id ?? 0),
        ),
      ),
    );
  }

  Row _price() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        Column(
          children: [
            Text(
              AppStrings.DOLLAR,
              style: TextStyle(
                fontSize: 10,
                color: AppColors.C_EC2010,
              ),
            ),
            SizedBox(height: 1.7),
          ],
        ),
        Text(
          "${_goodsEntity.retailPrice}",
          style: TextStyle(
            color: AppColors.C_EC2010,
            fontSize: 15,
            fontWeight: FontWeight.bold,
          ),
        ),
      ],
    );
  }
}
